package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "频道管理controller",tags = "频道管理controller")
@RestController  //@ResponseBody  +  @Controller
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    @ApiOperation(value = "根据条件分页查询",notes = "根据条件:name  status  进行查询，结果以ord升序排序")
    @PostMapping("/list")
    public ResponseResult findByQuery(@RequestBody ChannelDTO dto){
        return channelService.findByQuery(dto);
    }

    @ApiOperation(value = "保存频道")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel){
        return channelService.insert(channel);
    }

    @ApiOperation(value = "修改频道")
    @PostMapping("/upadte")
    public ResponseResult update(@RequestBody AdChannel channel){
        return channelService.update(channel);
    }

    @ApiOperation("删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return channelService.deleteById(id);
    }
}
